#include "LightSourceObject.hpp"
#include "MLImportance.hpp"

LightSourceObject::LightSourceObject(std::string lightProbeName) : PointLightsSampler(), HDRImageObject(lightProbeName)
{
	m_pImportance = NULL;
	FIBITMAP* pDIB = const_cast<FIBITMAP*>(getHDRIBitmap());
	setSize(FreeImage_GetWidth(pDIB), FreeImage_GetHeight(pDIB));
	generateImportanceMap();
}

unsigned int LightSourceObject::getImportanceAt(MVector2D point)
{
	return m_pImportance->getImportanceAt(point.x, point.y);
}

void LightSourceObject::generateImportanceMap()
{
	FIBITMAP* pDIB = const_cast<FIBITMAP*>(getHDRIBitmap());
	m_pImportance = new MLImportance(FreeImage_GetWidth(pDIB), FreeImage_GetHeight(pDIB));

	m_pImportance->buildMap(FreeImage_GetBits(pDIB), FreeImage_GetPitch(pDIB));
}

//EOF
